<!DOCTYPE html><html lang="cn" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>Gateway记录 | HustleLr</title><meta name="keywords" content="SpringCloud"><meta name="author" content="HustleLr"><meta name="copyright" content="HustleLr"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Gateway笔记概述  SpringCloud Gateway是SpringCloud的一个全新项目，给予Spring5.0+Spring Boot2.0和Project Reactor等技术开发的网关，它旨在为微服务架构提供一种简单有效的统一的API路由管理方式。 SpringCloud Gateway是基于WebFlux框架实现的，而WebFlux框架底层则使用了高性能的Reactor模式通">
<meta property="og:type" content="article">
<meta property="og:title" content="Gateway记录">
<meta property="og:url" content="http://greenfivebird.gitee.io/hustleblog/2022/07/11/Gateway%E8%AE%B0%E5%BD%95/index.html">
<meta property="og:site_name" content="HustleLr">
<meta property="og:description" content="Gateway笔记概述  SpringCloud Gateway是SpringCloud的一个全新项目，给予Spring5.0+Spring Boot2.0和Project Reactor等技术开发的网关，它旨在为微服务架构提供一种简单有效的统一的API路由管理方式。 SpringCloud Gateway是基于WebFlux框架实现的，而WebFlux框架底层则使用了高性能的Reactor模式通">
<meta property="og:locale">
<meta property="og:image" content="http://greenfivebird.gitee.io/hustleblog/img/gateway.webp">
<meta property="article:published_time" content="2022-07-11T08:28:45.000Z">
<meta property="article:modified_time" content="2022-07-11T08:38:53.412Z">
<meta property="article:author" content="HustleLr">
<meta property="article:tag" content="SpringCloud">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://greenfivebird.gitee.io/hustleblog/img/gateway.webp"><link rel="shortcut icon" href="/hustleblog/img/head.jpg"><link rel="canonical" href="http://greenfivebird.gitee.io/hustleblog/2022/07/11/Gateway%E8%AE%B0%E5%BD%95/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/hustleblog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/hustleblog/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Gateway记录',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-07-11 16:38:53'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.1"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">Loading...</div></div></div><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/hustleblog/img/head.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data is-center"><div class="data-item"><a href="/hustleblog/archives/"><div class="headline">Articles</div><div class="length-num">17</div></a></div><div class="data-item"><a href="/hustleblog/tags/"><div class="headline">Tags</div><div class="length-num">12</div></a></div><div class="data-item"><a href="/hustleblog/categories/"><div class="headline">Categories</div><div class="length-num">12</div></a></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/hustleblog/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/hustleblog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/hustleblog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/hustleblog/link/"><i class="fa-fw fas fa-link"></i><span> 外链</span></a></div><div class="menus_item"><a class="site-page" href="/hustleblog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/hustleblog/img/gateway.webp')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/hustleblog/">HustleLr</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/hustleblog/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/hustleblog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/hustleblog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/hustleblog/link/"><i class="fa-fw fas fa-link"></i><span> 外链</span></a></div><div class="menus_item"><a class="site-page" href="/hustleblog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Gateway记录</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2022-07-11T08:28:45.000Z" title="Created 2022-07-11 16:28:45">2022-07-11</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2022-07-11T08:38:53.412Z" title="Updated 2022-07-11 16:38:53">2022-07-11</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/hustleblog/categories/SpringCloud/">SpringCloud</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/hustleblog/categories/SpringCloud/Gateway/">Gateway</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Gateway记录"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="Gateway笔记"><a href="#Gateway笔记" class="headerlink" title="Gateway笔记"></a>Gateway笔记</h1><h3 id="概述"><a href="#概述" class="headerlink" title="概述"></a>概述</h3><blockquote>
<ul>
<li>SpringCloud Gateway是SpringCloud的一个全新项目，给予Spring5.0+Spring Boot2.0和Project Reactor等技术开发的网关，它旨在为微服务架构提供一种简单有效的统一的API路由管理方式。</li>
<li>SpringCloud Gateway是基于WebFlux框架实现的，而WebFlux框架底层则使用了高性能的Reactor模式通信框架Netty，【说穿了就是 SpringCloud Gateway是异步非阻塞式，响应式的框架】</li>
</ul>
</blockquote>
<p>Gateway主要负责反向代理、鉴权、流量控制、熔断、日志监控等</p>
<h3 id="特性"><a href="#特性" class="headerlink" title="特性"></a>特性</h3><p>SpringCloud Gateway具有如下特性</p>
<ul>
<li>基于SpringFrameword5，Project Reactor和SpringBoot2.0进行构建；</li>
<li>动态路由：能够匹配任何请求属性</li>
<li>可以对路由指定Predicate（断言）和Filter（过滤器）</li>
<li>集成Hystrix的断路器功能</li>
<li>集成SpringCloud的服务发现功能</li>
<li>易于编写的Predicate（断言）和Filter（过滤器）</li>
<li>请求限流功能</li>
<li>支持路径重写<h3 id="Gateway的三大核心概念与工作流程"><a href="#Gateway的三大核心概念与工作流程" class="headerlink" title="Gateway的三大核心概念与工作流程"></a>Gateway的三大核心概念与工作流程</h3><h5 id="1、Route（路由）"><a href="#1、Route（路由）" class="headerlink" title="1、Route（路由）"></a>1、Route（路由）</h5>路由是构建网关的基本模块，它由ID，目标URI（统一资源标识符），一系列的断言和过滤器组成，如果断言为true则匹配该路由。<h5 id="2、Predicate（断言）"><a href="#2、Predicate（断言）" class="headerlink" title="2、Predicate（断言）"></a>2、Predicate（断言）</h5>开发人员可以匹配Http请求中的所有内容（例如请求头或者请求参数），如果请求参数与断言相匹配则进行路由。<h5 id="3、Filter（过滤）"><a href="#3、Filter（过滤）" class="headerlink" title="3、Filter（过滤）"></a>3、Filter（过滤）</h5>指的是Spring框架中的GateFilter的实例，使用过滤器，可以在请求被路由之前或之后对请求进行修改。<h3 id="入门配置"><a href="#入门配置" class="headerlink" title="入门配置"></a>入门配置</h3><h5 id="1、创建gateway模块"><a href="#1、创建gateway模块" class="headerlink" title="1、创建gateway模块"></a>1、创建gateway模块</h5><h5 id="2、修改pom文件添加依赖"><a href="#2、修改pom文件添加依赖" class="headerlink" title="2、修改pom文件添加依赖"></a>2、修改pom文件添加依赖</h5><blockquote>
<p>注意添加依赖不要添加web-starter否则会报错</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-gateway<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h5 id="3、修改yml"><a href="#3、修改yml" class="headerlink" title="3、修改yml"></a>3、修改yml</h5><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">server:</span></span><br><span class="line">  <span class="attr">port:</span> <span class="number">9527</span></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">application:</span></span><br><span class="line">    <span class="attr">name:</span> <span class="string">cloud-gateway</span></span><br><span class="line"><span class="attr">eureka:</span></span><br><span class="line">  <span class="attr">instance:</span></span><br><span class="line">    <span class="attr">hostname:</span> <span class="string">cloud-gateway-service</span></span><br><span class="line">  <span class="attr">client:</span> <span class="comment">#服务提供者provider注册进eureka服务列表内</span></span><br><span class="line">    <span class="attr">service-url:</span></span><br><span class="line">      <span class="attr">register-with-eureka:</span> <span class="literal">true</span></span><br><span class="line">      <span class="attr">fetch-registry:</span> <span class="literal">true</span></span><br><span class="line">      <span class="comment">#      defaultZone: http://eureka7001.com:7001/eureka # 单机版</span></span><br><span class="line">      <span class="attr">defaultZone:</span> <span class="string">http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka</span> <span class="comment">#集群版</span></span><br></pre></td></tr></table></figure>
<h5 id="主启动类"><a href="#主启动类" class="headerlink" title="主启动类"></a>主启动类</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.wlr.cloud;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.SpringApplication;</span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.autoconfigure.SpringBootApplication;</span><br><span class="line"><span class="keyword">import</span> org.springframework.cloud.netflix.eureka.EnableEurekaClient;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> lrwang</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@version</span> 1.0</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span> 2022/7/7 19:28</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="meta">@EnableEurekaClient</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">GatewayMain9527</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        SpringApplication.run(GatewayMain9527.class, args);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="yml新增网关配置"><a href="#yml新增网关配置" class="headerlink" title="yml新增网关配置"></a>yml新增网关配置</h5><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">wlr_blog</span>  <span class="comment"># 路由id，唯一</span></span><br><span class="line">          <span class="attr">uri:</span> <span class="string">http://localhost:8001</span>  <span class="comment">#匹配后提供服务的路由地址</span></span><br><span class="line">          <span class="attr">predicates:</span></span><br><span class="line">            <span class="bullet">-</span> <span class="string">Path=/blog/**</span>   <span class="comment"># 断言</span></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">wlr_security</span></span><br><span class="line">          <span class="attr">uri:</span> <span class="string">http://localhost:7000</span></span><br><span class="line">          <span class="attr">predicates:</span></span><br><span class="line">            <span class="bullet">-</span> <span class="string">Path=/auth/**</span></span><br></pre></td></tr></table></figure></blockquote>
</li>
<li><strong>routes</strong>: 可以为controller中所有的rest接口做路由</li>
<li><strong>uri+predicate</strong>：拼接具体接口请求路径，uri就是需要映射到的端口</li>
<li><strong>predicate</strong>：断言就是去uri对应端口下面找相匹配的一个请求，如果找到了就返回true，可以用当前端口访问，找不到就返回false<h3 id="Gateway网关路由有两种配置方式"><a href="#Gateway网关路由有两种配置方式" class="headerlink" title="Gateway网关路由有两种配置方式"></a>Gateway网关路由有两种配置方式</h3><h5 id="在yml中的配置——上文"><a href="#在yml中的配置——上文" class="headerlink" title="在yml中的配置——上文"></a>在yml中的配置——上文</h5><h5 id="代码中注入RouteLocator的Bean"><a href="#代码中注入RouteLocator的Bean" class="headerlink" title="代码中注入RouteLocator的Bean"></a>代码中注入RouteLocator的Bean</h5><h3 id="进阶"><a href="#进阶" class="headerlink" title="进阶"></a>进阶</h3><h5 id="1、通过微服务名实现动态路由"><a href="#1、通过微服务名实现动态路由" class="headerlink" title="1、通过微服务名实现动态路由"></a>1、通过微服务名实现动态路由</h5>一个路由规则仅仅对应一个接口方法，在分布式集群的情况下，会有多台主机多个端口，我们不可能为每一个接口定义一个路由规则，我们在uri中添加lb://微服务名，具体如下<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">application:</span></span><br><span class="line">    <span class="attr">name:</span> <span class="string">cloud-gateway</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">discovery:</span></span><br><span class="line">        <span class="attr">locator:</span></span><br><span class="line">          <span class="string">enabled:true</span>  <span class="comment">#开启从注册中心动态创建路由的功能，利用微服务名进行路由</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">payment_routh</span></span><br><span class="line">          <span class="attr">uri:</span> <span class="string">lb://cloud-payment-service</span></span><br><span class="line">          <span class="attr">predicates:</span> </span><br><span class="line">            <span class="bullet">-</span> <span class="string">Path=/payment/get/**</span></span><br></pre></td></tr></table></figure>
<font color="red"><strong>注意</strong></font><br>uri中的lb://开头表示从注册中心获取服务，后面接的是需要转发到的服务名称，而且找到的服务实现负载均衡<h3 id="Predicate断言的使用"><a href="#Predicate断言的使用" class="headerlink" title="Predicate断言的使用"></a>Predicate断言的使用</h3>断言存在多种——Predicates，我们这里使用的是断言的[Path]，它是路由规则中的一个，但是实际上有多种断言<br><img src="https://note.youdao.com/yws/res/103/WEBRESOURCEfc261d763a917188367284658a43cb07" alt="image.png"><blockquote>
<p>每一个断言Predicate都有它独特的规则，多个Predicate断言是一个&amp;组合</p>
</blockquote>
</li>
<li>Spring Cloud Gateway 将路由匹配作为Spring WebFlux Handler Mapping 基础架构的一部分</li>
<li>Spring Cloud Gateway 包括许多内置的Route Predicate工厂，所有的这些Predicate都和Http请求的不同属性匹配，多个Route Predicate可以进行组合</li>
<li>Spring Cloud Gateway在创建route对象时，使用RoutePredicateFactory创建Predicate对象，Predicate对象可以赋值给Route，SpringCloud Gateway包括许多内置的Route Predicate Factories。</li>
<li>所有的这些谓词都匹配Http的请求的各种属性，多种谓词工厂可以组合，通过逻辑and<br><strong>官网链接</strong>：<a target="_blank" rel="noopener" href="https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.2.1.RELEASE/reference/html/#the-after-route-predicate-factory">https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.2.1.RELEASE/reference/html/#the-after-route-predicate-factory</a><h4 id="常用的Predicate断言"><a href="#常用的Predicate断言" class="headerlink" title="常用的Predicate断言"></a>常用的Predicate断言</h4><h5 id="After-Route-Predicate"><a href="#After-Route-Predicate" class="headerlink" title="After Route Predicate"></a>After Route Predicate</h5></li>
<li>匹配改断言时间之后的uri请求</li>
<li><code>- After=2021-09-28T19:14:51.514+08:00[Asia/Shanghai]</code><h5 id="Before-Route-Predicate"><a href="#Before-Route-Predicate" class="headerlink" title="Before Route Predicate"></a>Before Route Predicate</h5></li>
<li>匹配改断言时间之前的uri请求<h5 id="Between-Route-Predicate"><a href="#Between-Route-Predicate" class="headerlink" title="Between Route Predicate"></a>Between Route Predicate</h5></li>
<li>匹配改断言时间之间的uri请求</li>
<li><code>Between=2020-02-02T17:45:06.206+08:00[Asia/Shanghai],2020-03-25T18:59:06.206+08:00[Asia/Shanghai]</code><h5 id="Cookie-Route-Predicate"><a href="#Cookie-Route-Predicate" class="headerlink" title="Cookie Route Predicate"></a>Cookie Route Predicate</h5><figure class="highlight plaintext"><figcaption><span>Cookie</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br></pre></td><td class="code"><pre><span class="line">###### 利用curl命令发送Post/Get请求</span><br><span class="line">+ 不带cookie发送</span><br><span class="line">cmd直接输入就是不带cookie的</span><br><span class="line">```curl http://localhost:9527/payment/lb```</span><br><span class="line">+ 带cookie发送</span><br><span class="line">``` curl http://localhost:9527/payment/lb --cookie &quot;username=zzyy&quot;```</span><br><span class="line">##### Header Route Predicate</span><br><span class="line">##### Host Route Predicate</span><br><span class="line">##### Method Route Predicate</span><br><span class="line">##### Path Route Predicate</span><br><span class="line">##### Query Route Predicate</span><br><span class="line">### Filter的使用</span><br><span class="line">#### 1、Filter是什么</span><br><span class="line">指的是GatewayFilter的实例，使用过滤器，可以在请求被路由前或者之后对请求进行修改，Filter链：同事满足一系列的过滤链。</span><br><span class="line">路由过滤器可用于修改进入的HTTP请求和返回的HTTP响应，路由过滤器只能指定路由进行使用。</span><br><span class="line">**生命周期**：</span><br><span class="line">pre 在业务逻辑之前</span><br><span class="line">post 在业务逻辑之后</span><br><span class="line">**种类**：</span><br><span class="line">单一的：GatewayFilter</span><br><span class="line">全局的：GlobalFilter</span><br><span class="line">**官网**：https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.2.1.RELEASE/reference/html/#gatewayfilter-factories</span><br><span class="line">#### 自定义全局过滤器</span><br><span class="line">主要实现两个接口：GlobalFilter、Ordered</span><br><span class="line">```java</span><br><span class="line">package com.wlr.cloud.filter;</span><br><span class="line"></span><br><span class="line">import lombok.extern.slf4j.Slf4j;</span><br><span class="line">import org.springframework.cloud.gateway.filter.GatewayFilterChain;</span><br><span class="line">import org.springframework.cloud.gateway.filter.GlobalFilter;</span><br><span class="line">import org.springframework.core.Ordered;</span><br><span class="line">import org.springframework.http.HttpStatus;</span><br><span class="line">import org.springframework.stereotype.Component;</span><br><span class="line">import org.springframework.web.server.ServerWebExchange;</span><br><span class="line">import reactor.core.publisher.Mono;</span><br><span class="line"></span><br><span class="line">import java.util.Date;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * @author lrwang</span><br><span class="line"> * @version 1.0</span><br><span class="line"> * @date 2022/7/10 22:59</span><br><span class="line"> */</span><br><span class="line">@Component</span><br><span class="line">@Slf4j</span><br><span class="line">public class MyLogGatewayFilter implements GlobalFilter, Ordered &#123;</span><br><span class="line">    @Override</span><br><span class="line">    public Mono&lt;Void&gt; filter(ServerWebExchange exchange, GatewayFilterChain chain) &#123;</span><br><span class="line">        log.info(&quot;**************************come in MyLogGatewayFilter: &quot;+new Date());</span><br><span class="line">        //取出请求参数的uname对应的值</span><br><span class="line">        String uname=exchange.getRequest().getQueryParams().getFirst(&quot;uname&quot;);</span><br><span class="line">        //如果uname为空，就直接过滤掉，不走路由</span><br><span class="line">        if (uname==null)&#123;</span><br><span class="line">            log.info(&quot;***********************用户名为Null，非法用户o(╥﹏╥)o&quot;);</span><br><span class="line">            //判断该请求不通过时，给一个回应，返回</span><br><span class="line">            exchange.getResponse().setStatusCode(HttpStatus.NOT_ACCEPTABLE);</span><br><span class="line">            return exchange.getResponse().setComplete();</span><br><span class="line">        &#125;</span><br><span class="line">        //反之调用下一个过滤器，即是放行，</span><br><span class="line">        return chain.filter(exchange);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 当前过滤器的加载顺序，数字越小优先级越高</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    @Override</span><br><span class="line">    public int getOrder() &#123;</span><br><span class="line">        return 0;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
</ul>
<script type="text&#x2F;javascript" src="https://unpkg.com/kity@2.0.4/dist/kity.min.js"></script><script type="text&#x2F;javascript" src="https://unpkg.com/kityminder-core@1.4.50/dist/kityminder.core.min.js"></script><script defer="true" type="text&#x2F;javascript" src="https://unpkg.com/hexo-simple-mindmap@0.8.0/dist/mindmap.min.js"></script><link rel="stylesheet" type="text&#x2F;css" href="https://unpkg.com/hexo-simple-mindmap@0.8.0/dist/mindmap.min.css"></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a href="mailto:undefined">HustleLr</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="http://greenfivebird.gitee.io/hustleblog/2022/07/11/Gateway%E8%AE%B0%E5%BD%95/">http://greenfivebird.gitee.io/hustleblog/2022/07/11/Gateway%E8%AE%B0%E5%BD%95/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/hustleblog/tags/SpringCloud/">SpringCloud</a></div><div class="post_share"><div class="social-share" data-image="/hustleblog/img/gateway.webp" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/hustleblog/2024/04/17/%E4%BB%A3%E7%A0%81%E9%9A%8F%E6%83%B3%E5%BD%95Day-1/"><img class="prev-cover" src="/hustleblog/img/code.png" onerror="onerror=null;src='/hustleblog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">Previous Post</div><div class="prev_info">代码随想录Day 1</div></div></a></div><div class="next-post pull-right"><a href="/hustleblog/2022/04/01/%E6%9E%84%E5%BB%BA%E4%BA%8C%E5%8F%89%E6%A0%91/"><img class="next-cover" src="/hustleblog/img/%E4%BA%8C%E5%8F%89%E6%A0%91.webp" onerror="onerror=null;src='/hustleblog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">Next Post</div><div class="next_info">构建二叉树</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/hustleblog/img/head.jpg" onerror="this.onerror=null;this.src='/hustleblog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">HustleLr</div><div class="author-info__description"></div></div><div class="card-info-data is-center"><div class="card-info-data-item"><a href="/hustleblog/archives/"><div class="headline">Articles</div><div class="length-num">17</div></a></div><div class="card-info-data-item"><a href="/hustleblog/tags/"><div class="headline">Tags</div><div class="length-num">12</div></a></div><div class="card-info-data-item"><a href="/hustleblog/categories/"><div class="headline">Categories</div><div class="length-num">12</div></a></div></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>Announcement</span></div><div class="announcement_content">Welcome to Wlr's Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Catalog</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Gateway%E7%AC%94%E8%AE%B0"><span class="toc-number">1.</span> <span class="toc-text">Gateway笔记</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A6%82%E8%BF%B0"><span class="toc-number">1.0.1.</span> <span class="toc-text">概述</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%89%B9%E6%80%A7"><span class="toc-number">1.0.2.</span> <span class="toc-text">特性</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Gateway%E7%9A%84%E4%B8%89%E5%A4%A7%E6%A0%B8%E5%BF%83%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B"><span class="toc-number">1.0.3.</span> <span class="toc-text">Gateway的三大核心概念与工作流程</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1%E3%80%81Route%EF%BC%88%E8%B7%AF%E7%94%B1%EF%BC%89"><span class="toc-number">1.0.3.0.1.</span> <span class="toc-text">1、Route（路由）</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2%E3%80%81Predicate%EF%BC%88%E6%96%AD%E8%A8%80%EF%BC%89"><span class="toc-number">1.0.3.0.2.</span> <span class="toc-text">2、Predicate（断言）</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#3%E3%80%81Filter%EF%BC%88%E8%BF%87%E6%BB%A4%EF%BC%89"><span class="toc-number">1.0.3.0.3.</span> <span class="toc-text">3、Filter（过滤）</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%A5%E9%97%A8%E9%85%8D%E7%BD%AE"><span class="toc-number">1.0.4.</span> <span class="toc-text">入门配置</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1%E3%80%81%E5%88%9B%E5%BB%BAgateway%E6%A8%A1%E5%9D%97"><span class="toc-number">1.0.4.0.1.</span> <span class="toc-text">1、创建gateway模块</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2%E3%80%81%E4%BF%AE%E6%94%B9pom%E6%96%87%E4%BB%B6%E6%B7%BB%E5%8A%A0%E4%BE%9D%E8%B5%96"><span class="toc-number">1.0.4.0.2.</span> <span class="toc-text">2、修改pom文件添加依赖</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#3%E3%80%81%E4%BF%AE%E6%94%B9yml"><span class="toc-number">1.0.4.0.3.</span> <span class="toc-text">3、修改yml</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E4%B8%BB%E5%90%AF%E5%8A%A8%E7%B1%BB"><span class="toc-number">1.0.4.0.4.</span> <span class="toc-text">主启动类</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#yml%E6%96%B0%E5%A2%9E%E7%BD%91%E5%85%B3%E9%85%8D%E7%BD%AE"><span class="toc-number">1.0.4.0.5.</span> <span class="toc-text">yml新增网关配置</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Gateway%E7%BD%91%E5%85%B3%E8%B7%AF%E7%94%B1%E6%9C%89%E4%B8%A4%E7%A7%8D%E9%85%8D%E7%BD%AE%E6%96%B9%E5%BC%8F"><span class="toc-number">1.0.5.</span> <span class="toc-text">Gateway网关路由有两种配置方式</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%9C%A8yml%E4%B8%AD%E7%9A%84%E9%85%8D%E7%BD%AE%E2%80%94%E2%80%94%E4%B8%8A%E6%96%87"><span class="toc-number">1.0.5.0.1.</span> <span class="toc-text">在yml中的配置——上文</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E4%BB%A3%E7%A0%81%E4%B8%AD%E6%B3%A8%E5%85%A5RouteLocator%E7%9A%84Bean"><span class="toc-number">1.0.5.0.2.</span> <span class="toc-text">代码中注入RouteLocator的Bean</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%9B%E9%98%B6"><span class="toc-number">1.0.6.</span> <span class="toc-text">进阶</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1%E3%80%81%E9%80%9A%E8%BF%87%E5%BE%AE%E6%9C%8D%E5%8A%A1%E5%90%8D%E5%AE%9E%E7%8E%B0%E5%8A%A8%E6%80%81%E8%B7%AF%E7%94%B1"><span class="toc-number">1.0.6.0.1.</span> <span class="toc-text">1、通过微服务名实现动态路由</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Predicate%E6%96%AD%E8%A8%80%E7%9A%84%E4%BD%BF%E7%94%A8"><span class="toc-number">1.0.7.</span> <span class="toc-text">Predicate断言的使用</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E7%9A%84Predicate%E6%96%AD%E8%A8%80"><span class="toc-number">1.0.7.1.</span> <span class="toc-text">常用的Predicate断言</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#After-Route-Predicate"><span class="toc-number">1.0.7.1.1.</span> <span class="toc-text">After Route Predicate</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Before-Route-Predicate"><span class="toc-number">1.0.7.1.2.</span> <span class="toc-text">Before Route Predicate</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Between-Route-Predicate"><span class="toc-number">1.0.7.1.3.</span> <span class="toc-text">Between Route Predicate</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Cookie-Route-Predicate"><span class="toc-number">1.0.7.1.4.</span> <span class="toc-text">Cookie Route Predicate</span></a></li></ol></li></ol></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/hustleblog/2024/04/21/%E4%BB%A3%E7%A0%81%E9%9A%8F%E6%83%B3%E5%BD%95Day-2/" title="代码随想录Day 2"><img src="/hustleblog/img/code.png" onerror="this.onerror=null;this.src='/hustleblog/img/404.jpg'" alt="代码随想录Day 2"/></a><div class="content"><a class="title" href="/hustleblog/2024/04/21/%E4%BB%A3%E7%A0%81%E9%9A%8F%E6%83%B3%E5%BD%95Day-2/" title="代码随想录Day 2">代码随想录Day 2</a><time datetime="2024-04-20T16:31:56.000Z" title="Created 2024-04-21 00:31:56">2024-04-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/hustleblog/2024/04/17/%E4%BB%A3%E7%A0%81%E9%9A%8F%E6%83%B3%E5%BD%95Day-1/" title="代码随想录Day 1"><img src="/hustleblog/img/code.png" onerror="this.onerror=null;this.src='/hustleblog/img/404.jpg'" alt="代码随想录Day 1"/></a><div class="content"><a class="title" href="/hustleblog/2024/04/17/%E4%BB%A3%E7%A0%81%E9%9A%8F%E6%83%B3%E5%BD%95Day-1/" title="代码随想录Day 1">代码随想录Day 1</a><time datetime="2024-04-17T14:26:46.000Z" title="Created 2024-04-17 22:26:46">2024-04-17</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/hustleblog/2022/07/11/Gateway%E8%AE%B0%E5%BD%95/" title="Gateway记录"><img src="/hustleblog/img/gateway.webp" onerror="this.onerror=null;this.src='/hustleblog/img/404.jpg'" alt="Gateway记录"/></a><div class="content"><a class="title" href="/hustleblog/2022/07/11/Gateway%E8%AE%B0%E5%BD%95/" title="Gateway记录">Gateway记录</a><time datetime="2022-07-11T08:28:45.000Z" title="Created 2022-07-11 16:28:45">2022-07-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/hustleblog/2022/04/01/%E6%9E%84%E5%BB%BA%E4%BA%8C%E5%8F%89%E6%A0%91/" title="构建二叉树"><img src="/hustleblog/img/%E4%BA%8C%E5%8F%89%E6%A0%91.webp" onerror="this.onerror=null;this.src='/hustleblog/img/404.jpg'" alt="构建二叉树"/></a><div class="content"><a class="title" href="/hustleblog/2022/04/01/%E6%9E%84%E5%BB%BA%E4%BA%8C%E5%8F%89%E6%A0%91/" title="构建二叉树">构建二叉树</a><time datetime="2022-03-31T16:29:49.000Z" title="Created 2022-04-01 00:29:49">2022-04-01</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/hustleblog/2022/03/22/Java%E5%B8%B8%E8%A7%81%E5%87%A0%E7%A7%8D%E6%8E%92%E5%BA%8F/" title="Java常见几种排序"><img src="/hustleblog/img/sort.webp" onerror="this.onerror=null;this.src='/hustleblog/img/404.jpg'" alt="Java常见几种排序"/></a><div class="content"><a class="title" href="/hustleblog/2022/03/22/Java%E5%B8%B8%E8%A7%81%E5%87%A0%E7%A7%8D%E6%8E%92%E5%BA%8F/" title="Java常见几种排序">Java常见几种排序</a><time datetime="2022-03-22T09:51:45.000Z" title="Created 2022-03-22 17:51:45">2022-03-22</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/hustleblog/img/gateway.webp')"><div id="footer-wrap"><div class="copyright">&copy;2019 - 2024 By HustleLr</div><div class="footer_custom_text">Welcome to HustleLr's Blog</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="Toggle Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/hustleblog/js/utils.js"></script><script src="/hustleblog/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="true"></script><script id="click-show-text" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-show-text.min.js" data-mobile="false" data-text="有,志,者,事,竟,成" data-fontsize="15px" data-random="false" async="async"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>